/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.Timer;
import java.util.TimerTask;

/**
 * <p>Project: javaweb - MyTimerTask
 * <p>Powered by webrx On 2022-03-10 16:25:09
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
//@WebListener
public class MyTimerTask implements ServletContextListener {
    private Timer timer = null;
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("public void contextInitialized()");
        timer = new Timer(true);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.printf("%tF %<tT%n%n%n",System.currentTimeMillis());
            }
        },1000,5000);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("contextDestroyed");
        timer.cancel();
    }
}
